package com.greedy.order.service;

import com.greedy.feign.clients.UserClient;
import com.greedy.feign.pojo.User;
import com.greedy.order.mapper.OrderMapper;
import com.greedy.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: Greedy
 * @Date: Created in:2022-07-19 15:16
 * Description:
 */
@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserClient userClient;

    /**
     * 根据Id查询订单表所有数据
     * @param id
     * @return
     */
    public Order getOrderById(Long id) {
        // 1.查询order表
        Order order = orderMapper.getOrderById(id);
        // 2.feign发送Http请求到userController
        User user = userClient.getUserById(order.getUserId());
        // 3.封装user到order
        order.setUser(user);
        // 4.返回
        return order;
    }
}